package OtherMethod;

import java.util.ArrayList;
import java.util.List;

class Element {
	public String title;
	public double content;
	public Element(String title, double content) {
		this.title = title;
		this.content = content;
	}
	public boolean compareTitle(Element e) {
		return Integer.parseInt(this.title) > Integer.parseInt(e.title);
	}
	public boolean isEqualTitle(Element e) {
	    return (this.title.compareTo(e.title) == 0);
	}
	public boolean compareContent(Element e) {
		return this.content >= e.content;
	}
}
public class StatisticTable {
	
	protected List<Element> list = null;
	public StatisticTable() {
		this.list = new ArrayList<Element>();
	}
	
	public void ACT001_add(String title, double content) {
		boolean isAdd = false;
		Element newEle = new Element(title, content);
		if(this.list.size() == 0) {
			isAdd = true;
			this.list.add(0, newEle);
		}
		else if(this.list.get(0).compareContent(newEle)) {
			this.list.add(0, newEle);
			isAdd = true;
		}
		int index = 0;
		while(!isAdd && index < this.list.size() - 1) {
			Element curEle = this.list.get(index);
			if(newEle.compareContent(curEle) && this.list.get(index + 1).compareContent(newEle)) {
				isAdd = true;
				this.list.add(index + 1, newEle);
			}
			index = index + 1;
		}
		if(!isAdd) {
			this.list.add(this.list.size(), newEle);
		}
	}
	
	public void ACT002_showResult() {
		int index = 0;
		while(index < this.list.size()) {
			System.out.println(this.list.get(index).title + " " + this.list.get(index).content + "\n");
			index = index + 1;
		}
	}
	
	public List<Element> GET001_list() {
		return this.list;
	}
}
